#include "../FileLog.h"
#include <string>
#include <iostream>
#include <libbase/Singleton.h>
#include <unistd.h>
#include <stdint.h>

using namespace BASE;

class TestLog: public FileLog,public Singleton<TestLog>{
	public:
		TestLog(){

		}
};

class ThreadA: public Thread{
	public:
		ThreadA(){a = 0;}
		void thread(){
			TestLog * log = TestLog::get();
			pid_t pid = pthread_self();
			while(true){
				(*log)<< LEVEL_INFO << pid << "," << a << std::endl;
				++a;
				usleep(3000);
			}
		}
	private:
		int a;

};

class ThreadB: public Thread{
	public:
		ThreadB(){}

		void thread(){
			int64_t c = 0;
			TestLog * log = TestLog::get();
			pid_t pid = pthread_self();
			while(true){
				(*log) << LEVEL_INFO << pid <<"," << c << std::endl;
				++c;
				usleep(3000);
			}
		}
	private:
};

int main(){
	/*FileLog log;
	log.initialize("fileLogTest.log","filePipe.fifo");
	log << LEVEL_INFO << "log test" << std::endl;
	*/
	TestLog * log = TestLog::get();
	log->initialize("fileLogTest.log","filePipe.fifo", LEVEL_INFO);
	ThreadA a;
	a.start();
	ThreadB b;
	b.start();
	sleep(10);
	return 0;
}
